1. /* existdir.cpp by K. Tsuru*/
  2. /************************************
  3. It returns whether the directory exist or not.
  4. *************************************/
  5. #ifndef SN_H
  6. #include "sn.h"
  7. #endif
  8. static const char* const testFile ="$$$.$$$";
  9. bool ExistDirectory(const char* const dir){
  10. FILE* fp;
  11. char fname[SNC_MAX_PATH];
  12. bool create = true;
  13. strcpy(fname, dir);
  14. char* lc = LastChar(fname);
  15. if(*lc != DIR_SEPARATOR){ // no separator of directory
  16. *(lc+1) = DIR_SEPARATOR; *(lc+2) = '\0';
  17. }
  18. strcat(fname, testFile);
  19. fp = fopen(fname, "r"); // try to read
  20. if(fp == NULL) fp = fopen(fname, "w");// create
  21. else create = false;
  22. if(fp != NULL){
  23. fclose(fp); if(create) remove(fname); return true;
  24. }
  25. return false;
  26. }

existdir.cpp : last modifiled at 2017/12/24 15:29:49(757 bytes)
created at 2016/04/11 11:17:20
The creation time of this html file is 2017/12/24 15:31:13 (Sun Dec 24 15:31:13 2017).